﻿using System.Configuration;

namespace Pixeldyne.Core.Configuration
{
	/// <summary>
	/// Generic configuration element with "key" and "value" attributes.
	/// </summary>
	public class KeyValueElement : ConfigurationElement
	{
		const string KEY_ATTRIBUTE = "key";
		const string VALUE_ATTRIBUTE = "value";

		/// <summary>
		/// Initializes a new instance of the <see cref="KeyValueElement"/> class.
		/// </summary>
		/// <param name="newKey">The key.</param>
		/// <param name="newValue">The value.</param>
		public KeyValueElement(string newKey, string newValue)
		{
			Key = newKey;
			Value = newValue;
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="KeyValueElement"/> class.
		/// </summary>
		/// <param name="newKey">The key.</param>
		public KeyValueElement(string newKey)
		{
			Key = newKey;
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="KeyValueElement"/> class.
		/// </summary>
		public KeyValueElement()
		{
		}

		/// <summary>
		/// Gets or sets the type.
		/// </summary>
		/// <value>The key.</value>
		[ConfigurationProperty(KEY_ATTRIBUTE, IsRequired = true, IsKey = true)]
		public string Key
		{
			get
			{
				return (string)this[KEY_ATTRIBUTE];
			}

			set
			{
				this[KEY_ATTRIBUTE] = value;
			}
		}

		/// <summary>
		/// Gets or sets the value.
		/// </summary>
		/// <value>The value.</value>
		[ConfigurationProperty(VALUE_ATTRIBUTE, IsRequired = true)]
		public string Value
		{
			get
			{
				return (string)this[VALUE_ATTRIBUTE];
			}

			set
			{
				this[VALUE_ATTRIBUTE] = value;
			}
		}
	}
}
